<template>
  <div class="shouPiaoYuanPKCYXC">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="refreshChange">
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <!-- <template slot="search" slot-scope="{row,size}" >
          <el-form-item label="差异金额范围" labelWidth="150px" style="width:450px">
            <el-input-number v-model="searchForm.replyErrorReturnMoneyStart" :min="0" :max="99999998" label="差异金额范围" clearable></el-input-number>~
            <el-input-number v-model="searchForm.replyErrorReturnMoneyEnd" :min="1" :max="99999999" label="差异金额范围" clearable></el-input-number>
          </el-form-item>
        </template>-->
        <template slot-scope="scope" slot="conductorPersonCodeSearch">
          <el-select v-model="searchForm.conductorPersonCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in userList"
              :key="index"
              :label="item.nikename"
              :value="item.userCode">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="equipmentNumberSearch">
          <el-select v-model="searchForm.equipmentNumber" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in equipmentNumberList"
              :key="index"
              :label="item.operationCode"
              :value="item.operationCode">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small" plain @click.stop="previewEditor(scope.row,2)">预览</el-button>
          <el-button type="text" size="small"
                     v-if="(scope.row.assistState==4 || scope.row.assistState==9) && permissionList.ticketAuditApprove"
                     plain @click.stop="ticketAuditApproveOption(scope.row)">审核通过</el-button><!-- 票务审核通过-->
          <el-button type="text" size="small"
                     v-if="(scope.row.assistState==4 || scope.row.assistState==9) && permissionList.ticketAuditReject"
                     plain @click.stop="ticketAuditReject(scope.row)">驳回</el-button><!-- 票务审核驳回-->
          <el-button type="text" size="small"
                     v-if="scope.row.assistState==6 && permissionList.departmentAuditApprove"
                     plain @click.stop="departmentAuditApproveOption(scope.row)">审核通过</el-button><!-- 部门审核通过-->
          <el-button type="text" size="small"
                     v-if="scope.row.assistState==6 && permissionList.departmentAuditReject"
                     plain @click.stop="departmentAuditReject(scope.row)">驳回</el-button><!-- 部门审核驳回-->

        </template>
        <template slot="menuRight">
          <el-button type="primary"  size="mini" @click="exportData" v-if="false">导出</el-button>
        </template>
      </avue-crud>

      <open-dialog
        :DialogVisible.sync="ticketAuditRejectShow"
        title="车间票务专业审核意见"
        width="60%"
      >
        <el-form v-if="ticketAuditRejectShow">
          <avue-form
            v-model="ticketAuditRejectForm"
            :option="ticketAuditRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="subForm">保存</el-button>
          <el-button type="primary" @click="ticketAuditRejectShow = false" >取消</el-button>
        </div>
      </open-dialog>

      <open-dialog
        :DialogVisible.sync="ticketAuditRejectOptionShow"
        title="车间票务专业审核意见"
        width="60%"
      >
        <el-form v-if="ticketAuditRejectOptionShow">
          <avue-form
            v-model="ticketAuditRejectForm"
            :option="ticketAuditRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="ticketAuditApprove">保存</el-button>
          <el-button type="primary" @click="ticketAuditRejectOptionShow = false" >取消</el-button>
        </div>
      </open-dialog>
      <open-dialog
        :DialogVisible.sync="departmentAuditRejectShow"
        title="部门票务专业审核意见"
        width="60%"
      >
        <el-form v-if="departmentAuditRejectShow">
          <avue-form
            v-model="departmentAuditRejectForm"
            :option="departmentAuditRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="subDeptForm">保存</el-button>
          <el-button type="primary" @click="departmentAuditRejectShow = false" >取消</el-button>
        </div>
      </open-dialog>

      <open-dialog
        :DialogVisible.sync="departmentAuditRejectOptionShow"
        title="部门票务专业审核意见"
        width="60%"
      >
        <el-form v-if="departmentAuditRejectOptionShow">
          <avue-form
            v-model="departmentAuditRejectForm"
            :option="departmentAuditRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="departmentAuditApprove">保存</el-button>
          <el-button type="primary" @click="departmentAuditRejectOptionShow = false" >取消</el-button>
        </div>
      </open-dialog>
    </basic-container>
    <HuikuiInfo ref="HuikuiInfo" v-if="isShowDia"></HuikuiInfo>
    <HuikuiInfoBatchFeedback ref="HuikuiInfoBatchFeedback" v-if="isShowDiaBatchFeedback"></HuikuiInfoBatchFeedback>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {ticketAuditRejectOption,departmentAuditRejectOption} from "@/const/crud/zhanNeiRYDLCK";
  import {mapGetters} from 'vuex';
  import HuikuiInfo from './HuikuiInfo';
  import HuikuiInfoBatchFeedback from './HuikuiInfoBatchFeedback';
  import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
  import {
    setSearchFiledsEmpty,
    getSwPmDeviceOperationCodeList,
    getSysUserToLS,
    getStationByCode, getLineAllAsyn,getLineCodes
  } from "../../../../api/subwayRat/commonCheck";
  import {auditShouPiaoYuanPKCYXC} from '../../../../api/stationTiecketManager/shuJuXieChaGuanLi/BOM/shouPiaoYuanPKCYXC'
  import {tableOption,getSwAuConductorToBeCheckedList} from '../../../../api/stationTiecketManager/shuJuXieChaGuanLi/BOM/shouPiaoYuanPKCYXCOther';
  import {get_xw_spy_otherYunYingZXDLCK_Option} from "../../../../api/stationTiecketManager/xianWngCJXXQR/shouPiaoYuanPKCY/shouPiaoYuanPKCYQRTZ/otherYunYingZXDLCK";
  export default {
    name: 'shouPiaoYuanPKCYXC',
    components:{
      HuikuiInfo,HuikuiInfoBatchFeedback
    },
    data() {
      return {
        departmentAuditRejectOption: departmentAuditRejectOption,
        departmentAuditRejectForm: {},
        departmentAuditRejectShow: false,
        departmentAuditRejectOptionShow: false,
        ticketAuditRejectOption: ticketAuditRejectOption,
        ticketAuditRejectForm: {},
        ticketAuditRejectShow:false,
        ticketAuditRejectOptionShow:false,
        isShowDia:false,
        isShowDiaBatchFeedback:false,
        option: tableOption,
        listLoading: true,
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        lineCodes:[],
        stationCodes:[],
        searchForm:{
          lineCode:'9',
          stationCode:'',
          conductorPersonCode:'',
          equipmentNumber:''},

        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : [],
        userList:[],
        equipmentNumber:[],
        showType : 0,
        equipmentNumberList : [],
        batchFeedbackList : []
      }
    },
    computed: {
      ...mapGetters(['permissions']),
      permissionList () {
        return {
          ticketAuditApprove: this.vaildData(
            this.permissions.shouPiaoYuanPKCYXCOther_AUDIT_WORKSHOP_PASS,
            false
          ),
          ticketAuditReject: this.vaildData(
            this.permissions.shouPiaoYuanPKCYXCOther_AUDIT_WORKSHOP_REJECT,
            false
          ),
          departmentAuditApprove: this.vaildData(
            this.permissions.shouPiaoYuanPKCYXCOther_AUDIT_DEPT_PASS,
            false
          ),
          departmentAuditReject: this.vaildData(
            this.permissions.shouPiaoYuanPKCYXCOther_AUDIT_DEPT_REJECT,
            false
          ),
        };
      },
    },
    watch: {
    },
    mounted() {
     // let p = {
     //    line_code : this.$store.getters.userInfo.lineCode,
     //    station_code : this.$store.getters.userInfo.stationCode
     //  };
     //  getSysUserToLS(p).then((response)=>{
     //    this.userList = response.data.data;
     //  });
      // getLineAllAsyn().then(res=>{ //获取线路
      //   this.lineCodes=res.data;
      // });
      getLineCodes().then(res=>{ //获取线路
          this.lineCodes=res;
      });
    },
    created() {
      this.changeLine("9")
      //this.option=get_xw_spy_otherYunYingZXDLCK_Option();
      this.getSheBei();

    },
    methods: {
      setSearchFiledsEmpty,
      batchFeedback(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要回馈的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(1 == this.selectKeys[i].kyReplySatus){
            this.$message.warning("勾选数据中存在车站已回馈数据！");
            return
          }
        }
        this.batchFeedbackList = this.selectKeys;
        this.isShowDiaBatchFeedback = true;
      },

      refreshChange() {
        this.getList()
      },

      ticketAuditApprove(row){
        let th=this;
        if (this.ticketAuditRejectForm.auditWorkshopOpinion == null || this.ticketAuditRejectForm.auditWorkshopOpinion == '') {
          th.$message.error("请填写审核意见！");
          return false;
        }
        auditShouPiaoYuanPKCYXC({
          id:this.ticketAuditRejectForm.id,
          assistState:6,
          auditWorkshopOpinion:this.ticketAuditRejectForm.auditWorkshopOpinion
        }).then(res=>{
          th.$message.success("审核成功！");
          this.ticketAuditRejectOptionShow=false;
          th.getList();
        })
          .catch(() => {
            // th.$message.error("票务审核失败！");
            return false;
          });
      },

      ticketAuditReject: function (row){
        this.ticketAuditRejectShow=true;
        this.ticketAuditRejectForm = row;
      },

      ticketAuditApproveOption: function (row){
        this.ticketAuditRejectOptionShow=true;
        this.ticketAuditRejectForm = row;
      },

      subForm(){
        let th=this;
        auditShouPiaoYuanPKCYXC({
          id:this.ticketAuditRejectForm.id,
          assistState:7,
          auditWorkshopOpinion:this.ticketAuditRejectForm.auditWorkshopOpinion
        }).then(res=>{
          th.$message.success("审核成功！");
          this.ticketAuditRejectShow=false;
          th.getList();
        })
          .catch(() => {
            // th.$message.error("票务审核失败！");
            return false;
          });
      },

      departmentAuditApprove(row){
        let th=this;
        if (this.departmentAuditRejectForm.auditDeptOpinion == null || this.departmentAuditRejectForm.auditDeptOpinion == '') {
          th.$message.error("请填写审核意见！");
          return false;
        }
        auditShouPiaoYuanPKCYXC({
          id:this.departmentAuditRejectForm.id,
          assistState:8,
          auditDeptOpinion:this.departmentAuditRejectForm.auditDeptOpinion
        }).then(res=>{
          th.$message.success("审核成功！");
          this.departmentAuditRejectOptionShow=false;
          th.getList();
        })
          .catch(() => {
            // th.$message.error("部门审核失败！");
            return false;
          });
      },

      departmentAuditReject: function (row){
        this.departmentAuditRejectShow=true;
        this.departmentAuditRejectForm = row;
      },

      departmentAuditApproveOption: function (row){
        this.departmentAuditRejectOptionShow=true;
        this.departmentAuditRejectForm = row;
      },

      subDeptForm(){
        let th=this;
        auditShouPiaoYuanPKCYXC({
          id:this.departmentAuditRejectForm.id,
          assistState:9,
          auditDeptOpinion:this.departmentAuditRejectForm.auditDeptOpinion
        }).then(res=>{
          th.$message.success("审核成功！");
          this.departmentAuditRejectShow=false;
          th.getList();
        })
          .catch(() => {
            // th.$message.error("部门审核失败！");
            return false;
          });
      },

      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      async exportData(){ // 导出
        this.searchForm.pageNo=1;
        this.searchForm.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'售票员票款差异协查');
        }else {
          let res=await getSwAuConductorToBeCheckedList(this.searchForm);
          let data = res.data.data.list;
          exportDataToExcel(data,this.option.column,'售票员票款差异协查');
        }
      },
      previewEditor(row,type){
        this.showType = type;
        this.isShowDia=true;
        this.$nextTick(()=>{
          this.$refs.HuikuiInfo.recallShow(row);
        })
      },
      async getSheBei(){
        let res=[];
        await getSwPmDeviceOperationCodeList({lineCode:this.$store.getters.userInfo.lineCode,stationCode:this.$store.getters.userInfo.stationCode}).then(r=>{
          res=r.data.data;
        });
        this.equipmentNumberList=res;
        return res;
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        //this.searchForm.kyAssistInvestStatusss = "2,3";
	this.searchForm.assistCategoryRole='dept';
        getSwAuConductorToBeCheckedList(this.searchForm).then((response)=>{
          this.list = response.data.data.list;
          this.listLoading = false;
          this.page.total=response.data.data.pageInfo.total;
        });
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList();
        done()
      },
      changeLine(v){ //改变线路时
        getStationByCode({line_code:v}).then(res=>{
          this.stationCodes=res.data;
          this.searchForm.stationCode='';
          this.searchForm.conductorPersonCode = '';
          this.searchForm.equipmentNumber = '';
        });
      },
      changeStation(v){
        getSysUserToLS({stationCode:v}).then((res)=>{
          this.userList=res.data.data
          this.searchForm.conductorPersonCode = '';
        });
        getSwPmDeviceOperationCodeList({stationCode:v}).then((res)=>{
          this.equipmentNumberList=res.data.data;
        });
      },
    }
  }
</script>
